//
//  ProductDisplayViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-6-2.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "ProductDisplayViewController.h"
#import "ProductDisplayTableViewCell.h"
#import "SearchProductTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "UpCounterDetailTableViewCell.h"
#import "GuideListTableViewCell.h"
#import "EGORefreshTableHeaderView.h"
#import "CommonScanViewController.h"
#import "FilterViewController.h"
#import "CommonProductDetailViewController.h"
@interface ProductDisplayViewController ()<EGORefreshTableHeaderDelegate,CommonScanDelegate,FilterViewControllerDelegate,CommonProductDetailDelegate>
{
    FilterViewController *filterVC;
    CommonScanViewController *commonScanVC;
    CommonProductDetailViewController *commonProductDetailVC;
    EGORefreshTableHeaderView *_refreshHeaderView;
    BOOL _reloading;

    NSUInteger _PageIndex;
    NSUInteger _TotalCount;
    NSUInteger _TotalPage;
    
    NSUInteger _productPageIndex;
    NSUInteger _productTotalCount;
    NSUInteger _productTotalPage;
    
    NSMutableArray *displayProductNameArray;
    NSMutableArray *displayNumArray;
    NSMutableArray *displayWeightArray;
    NSMutableArray *displayNumberArray;
    NSMutableArray *displayGuideNameArray;
    NSMutableArray *displayDateArray;
    NSMutableArray *displayStatusArray;
    NSMutableArray *displayPriceArray;
    
    NSUInteger searchProductCellTag;
    BOOL guideIsOpen;
    
    NSMutableArray *selectedProductImageArray;
    NSMutableArray *selectedProductWeightArray;
    NSMutableArray *selectedProductPriceArray;
    NSMutableArray *selectedProductNameArray;
    NSMutableArray *selectedProductCodeArray;
    NSMutableArray *selectProductWhereArray;
    
    NSMutableArray *guideNameArray;
    NSMutableArray *guideCodeArray;
    NSString *guideCodeStr;
    
    NSMutableArray *detailUrlArray;
    NSMutableArray *detailProductNameArray;
    NSMutableArray *detailProductCodeArray;
    NSMutableArray *detailLinePriceArray;
    NSMutableArray *detailWeightArray;
    NSMutableArray *detailAttributesArray;
    NSMutableArray *detailWhereArray;
    
    NSString *upOrDownCounterStr;
    NSString *typeStr;

    UITextField *inputTextField;
    
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSMutableArray *selectFilterCodeArray;
    NSMutableArray *selectFilterNameArray;
    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    NSString *startTimeStr;
    NSString *endTimeStr;

}
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@end

@implementation ProductDisplayViewController
-(void)viewWillAppear:(BOOL)animated
{
    if ([_isLoad isEqualToString:@"N"]) {
    if (commonProductDetailVC.view!=nil) {
            
            [commonProductDetailVC removeFromParentViewController];
            [commonProductDetailVC.view removeFromSuperview];
            
        }

    if (commonScanVC.view!=nil) {
        if (commonScanVC.timer!=nil) {
            [commonScanVC.timer invalidate];
            commonScanVC.timer=nil;
        }
        if (commonScanVC.captureSession!=nil) {
            
            
            [commonScanVC.captureSession stopRunning];
            commonScanVC.captureSession = nil;
        }
        if (commonScanVC.videoPreviewLayer !=nil) {
            
            
            [commonScanVC.videoPreviewLayer removeFromSuperlayer];
        }
        

        [commonScanVC.view removeFromSuperview];
        [commonScanVC removeFromParentViewController];
        
    }
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }

    _upCounterBtn.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _upCounterBtn.layer.borderWidth= 1.0f;
    _upCounterBtn.layer.cornerRadius=3;
    
    [_upCounterBtn addTarget:self action:@selector(upCounterBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    _downCounterBtn.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _downCounterBtn.layer.borderWidth= 1.0f;
    _downCounterBtn.layer.cornerRadius=3;
     [_downCounterBtn addTarget:self action:@selector(upCounterBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self initDisplayList];
    [self initUpCounterViewContainer];
    [self initDetailViewContainer];
    [self initOrderFilterView];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
    }

}
-(void)initOrderFilterView
{
    inputFilterCodeArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
    selectFilterNameArray=[NSMutableArray array];
    selectCustomTimeArray=[NSMutableArray array];
    
    startTimeStr=@"";
    endTimeStr=@"";
    
    [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
    [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    // [_orderFilterViewContainer bringSubviewToFront:_resetFilterBtn];
    
    _orderFilterBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _orderFilterBtn.layer.borderWidth= 1.0f;
    _orderFilterBtn.layer.cornerRadius=4;
    
    [_orderFilterBtn addTarget:self action:@selector(orderFilterBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)orderFilterBtnClick
{
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    filterVC=[[FilterViewController alloc] init];
    filterVC.delegate=self;
    filterVC.docTypeStr=@"DCount";
    filterVC.selectCustomTimeArray=[NSMutableArray arrayWithArray:selectCustomTimeArray];
    filterVC.startTimeStr=startTimeStr;
    filterVC.endTimeStr=endTimeStr;
    // NSLog(@"selectFilterNameArray=22222======%@",selectFilterNameArray);
    filterVC.selectFilterNameArray=[NSMutableArray arrayWithArray:selectFilterNameArray];
    filterVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:filterVC];
    [self.view addSubview:filterVC.view];
}
-(void)confirmFilterBtnClick:(NSMutableArray *)commonFilterTypeCodeArray commonSelectFilterCodeArray:(NSMutableArray *)commonSelectFilterCodeArray commonInputFilterCodeArray:(NSMutableArray *)commonInputFilterCodeArray commonInputMinResultFilterNameArray:(NSMutableArray *)commonInputMinResultFilterNameArray commonInputMaxResultFilterNameArray:(NSMutableArray *)commonInputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:(NSMutableArray *)commonCustomTimeFilterTypeCodeArray commonSelectCustomTimeArray:(NSMutableArray *)commonSelectCustomTimeArray commonSelectFilterNameArray:(NSMutableArray *)commonSelectFilterNameArray  commonStartTimeStr:(NSString *)commonStartTimeStr commonEndTimeStr:(NSString *)commonEndTimeStr isDefault:(NSString *)isDefault
{
    
    if ([isDefault isEqualToString:@"Y"]) {
        //  NSLog(@"_isDefault0000===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    }
    else{
        // NSLog(@"_isDefault1111===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:203.0f/255.0f green:164.0f/255.0f blue:67.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"yishaixuan_.png"]];
    }
    
    filterTypeCodeArray=commonFilterTypeCodeArray;
    selectFilterCodeArray=commonSelectFilterCodeArray;
    inputFilterCodeArray=commonInputFilterCodeArray;
    inputMinResultFilterNameArray=commonInputMinResultFilterNameArray;
    inputMaxResultFilterNameArray=commonInputMaxResultFilterNameArray;
    customTimeFilterTypeCodeArray=commonCustomTimeFilterTypeCodeArray;
    selectCustomTimeArray=commonSelectCustomTimeArray;
    selectFilterNameArray=commonSelectFilterNameArray;
    
    startTimeStr=commonStartTimeStr;
    endTimeStr=commonEndTimeStr;
    
    
    [displayNumArray removeAllObjects];
    [displayWeightArray removeAllObjects];
    [displayNumberArray removeAllObjects];
    [displayProductNameArray removeAllObjects];
    [displayGuideNameArray removeAllObjects];
    [displayDateArray removeAllObjects];
    [displayStatusArray removeAllObjects];
    [displayPriceArray removeAllObjects];
    
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
    
}
-(void)initDetailViewContainer
{
    [_detailScrollview setContentOffset:CGPointMake(0, 0)];
    detailUrlArray=[NSMutableArray array];
    detailProductNameArray=[NSMutableArray array];
    detailProductCodeArray=[NSMutableArray array];
    detailLinePriceArray=[NSMutableArray array];
    detailWeightArray=[NSMutableArray array];
    detailAttributesArray=[NSMutableArray array];
    detailWhereArray=[NSMutableArray array];

    [_upCounterDetailAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_upCounterDetailAlphaView addTarget:self action:@selector(upCounterDetailAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    CGRect viewFrame=_upCounterDetailViewContainer.frame;
    viewFrame.origin.y=768;
    _upCounterDetailViewContainer.frame=viewFrame;

}
-(void)initUpCounterViewContainer
{
    guideCodeStr=@"";
    
    selectedProductImageArray=[NSMutableArray array];
    selectedProductWeightArray=[NSMutableArray array];
    selectedProductPriceArray=[NSMutableArray array];
    selectedProductNameArray=[NSMutableArray array];
    selectedProductCodeArray=[NSMutableArray array];
    selectProductWhereArray=[NSMutableArray array];
    
    guideNameArray=[NSMutableArray array];
    guideCodeArray=[NSMutableArray array];


    _resultTextView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _resultTextView.layer.borderWidth= 1.0f;
    _resultTextView.layer.cornerRadius=3;

    CGRect viewFrame=_upCounterViewContainer.frame;
    viewFrame.origin.y=768;
    _upCounterViewContainer.frame=viewFrame;
    
    
    [_upCounterResultAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_upCounterResultAlphaView addTarget:self action:@selector(upCounterResultAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    _resultGuideListBtn.tag=60;
    [_resultGuideListBtn addTarget:self action:@selector(selectGuideBtnClick:) forControlEvents:UIControlEventTouchUpInside];

    
    CGRect viewFrame1=_upCounterViewContainer.frame;
    viewFrame1.origin.y=768;
    _upCounterViewContainer.frame=viewFrame1;
       
    
    guideIsOpen=NO;
}
-(void)upCounterDetailAlphaViewClick
{
    [_searchTextField resignFirstResponder];
    
    [_resultTextField resignFirstResponder];
    [_resultTextView resignFirstResponder];
    [_detailScrollview setContentOffset:CGPointMake(0, 0)];
    [UIView animateWithDuration:0.5 animations:^{
        
       
        CGRect frame=_upCounterDetailViewContainer.frame;
        
        frame.origin.y=768;
        [_upCounterDetailViewContainer setFrame:frame];
        
    } completion:^(BOOL finished){
      
    }];
 
}
-(void)selectGuideBtnClick:(UIButton *)sender
{
    if (sender.tag==60) {
        
        
        if (guideIsOpen) {
            _resultGuideListViewContainer.hidden=YES;
            [UIView animateWithDuration:0.5 animations:^{
                
                UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
                [_resultGuideListArrowImage setImage:closeImage];
                CGRect frame=_resultGuideListViewContainer.frame;
                
                frame.size.height=1;
                [_resultGuideListViewContainer setFrame:frame];
                
            } completion:^(BOOL finished){
                guideIsOpen=NO;
            }];
            
        }
        else
        {
            [self requestGuideList];
            _resultGuideListViewContainer.hidden=NO;
            [UIView animateWithDuration:0.5 animations:^{
                UIImage *closeImage=[UIImage imageNamed:@"jiantou_upward.png"];
                
                
                [_resultGuideListArrowImage setImage:closeImage];
                CGRect frame=_resultGuideListViewContainer.frame;
                
                frame.size.height=657;
                [_resultGuideListViewContainer setFrame:frame];
                
            } completion:^(BOOL finished){
                guideIsOpen=YES;
            }];
            
        }
    }
}
-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"Guide/GuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [guideCodeArray removeAllObjects];
                    [guideNameArray removeAllObjects];
                  NSMutableArray *mGuidesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [guideCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserCode"]];
                        [guideNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    
                    [_resultGuideListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
//                    UIViewController *controller=[[GlobalViewController alloc]init];
//                    [self.navigationController pushViewController:controller animated:YES];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}


-(void)upCounterResultAlphaViewClick
{
    [_searchTextField resignFirstResponder];
    [_resultTextField resignFirstResponder];
    [_resultTextView resignFirstResponder];

    [_resultScrollview setContentOffset:CGPointMake(0, 0)];

    
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_upCounterViewContainer.frame;
         viewFrame.origin.y=768;
         _upCounterViewContainer.frame=viewFrame;
         
         CGRect viewFrameA=_upCounterResultView.frame;
         viewFrameA.origin.y=0;
         _upCounterResultView.frame=viewFrameA;
         
     }completion:^(BOOL finished) {
         
     }];
    
}

-(void)upCounterSearchAlphaViewClick
{
    [_searchTextField resignFirstResponder];
    
    [_resultTextField resignFirstResponder];
    [_resultTextView resignFirstResponder];

    CGRect viewFrame1=_upCounterViewContainer.frame;
    viewFrame1.origin.y=0;
    _upCounterViewContainer.frame=viewFrame1;
    
  
//    [UIView animateWithDuration:0.5f animations:^
//     {
//         CGRect viewFrame=_upCounterViewContainer.frame;
//         viewFrame.origin.y=768;
//         _upCounterViewContainer.frame=viewFrame;
//     }completion:^(BOOL finished) {
//         
//         
//     }];

}
-(void)upCounterBtnClick:(UIButton *)sender
{
   _resultTextField.text=@"";
    [_searchTextField resignFirstResponder];
    _resultNoteView.hidden=NO;
   
    guideCodeStr=[Global getGuideCodeStr];
    _resultGuideNameLabel.text=[Global getGuideNameStr];
    
    [Global resizeForLable:_resultGuideNameLabel WithText:_resultGuideNameLabel.text parentView:self.view];
    CGRect frameK=_resultGuideNameLabel.frame;
    frameK.origin.x=_resultGuideListArrowImage.frame.origin.x-frameK.size.width-5;
    _resultGuideNameLabel.frame=frameK;
    
    _resultGuideListViewContainer.hidden=YES;
   
        
        UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
        [_resultGuideListArrowImage setImage:closeImage];
        CGRect frame5=_resultGuideListViewContainer.frame;
        
        frame5.size.height=1;
        [_resultGuideListViewContainer setFrame:frame5];
    
    [guideCodeArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [_resultGuideListTableView reloadData];
    
    [selectedProductImageArray removeAllObjects];
    [selectedProductWeightArray removeAllObjects];
    [selectedProductPriceArray removeAllObjects];
    [selectedProductNameArray removeAllObjects];
    [selectedProductCodeArray removeAllObjects];
    [selectProductWhereArray removeAllObjects];
    [_resultTableView reloadData];
    _lastTotalLabel.text=[NSString stringWithFormat:@"共0件,0.00g"];
    _resultTextView.text=@"";
    _resultTextViewImage.hidden=NO;
    _resultTextViewLabel.hidden=NO;
    
    CGRect frame0=_resultTableView.frame;
    frame0.size.height=120;
    _resultTableView.frame=frame0;
    
    CGRect frame2=_lastView.frame;
    frame2.origin.y=301;
    _lastView.frame=frame2;
    
//        CGRect frame3=_lastView1.frame;
//        frame3.origin.y=704;
//        _lastView1.frame=frame3;
    
  
    
    //if (_lastView.frame.size.height+_lastView.frame.origin.y>768) {
    
    
    [_resultScrollview setContentSize:CGSizeMake(0, _lastView.frame.origin.y+ _lastView.frame.size.height+50)];
    [_resultScrollview setScrollEnabled:YES];

    if (sender.tag==200) {
        typeStr=@"UCounter";
       
       _resultNoteLabel.text=@"请搜索产品开始上柜";
        [_confirmUpCounterOrDownCounterBtn setTitle:@"确认上柜" forState:UIControlStateNormal];
        upOrDownCounterStr=@"U";
    }
    if (sender.tag==201) {
         typeStr=@"DCounter";
        upOrDownCounterStr=@"D";
       
         _resultNoteLabel.text=@"请搜索产品开始下柜";
         [_confirmUpCounterOrDownCounterBtn setTitle:@"确认下柜" forState:UIControlStateNormal];
    }
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_upCounterViewContainer.frame;
         viewFrame.origin.y=0;
         _upCounterViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
         
     }];
    
  
    [_resultGuideListArrowImage setImage:closeImage];
    
}
-(void)initDisplayList
{
    _searchTextField.text=@"";
   displayProductNameArray=[NSMutableArray array];
   displayNumArray=[NSMutableArray array];
   displayWeightArray=[NSMutableArray array];
   displayNumberArray=[NSMutableArray array];
   displayGuideNameArray=[NSMutableArray array];
   displayDateArray=[NSMutableArray array];
   displayStatusArray=[NSMutableArray array];
    displayPriceArray=[NSMutableArray array];
}
-(void) loadProductNextPage:(NSUInteger)oldPageNum {
   //NSLog(@"111111111");
    if(oldPageNum!=0 && _productTotalCount<=displayNumArray.count)
        return;
    if(oldPageNum == 0){
        [displayNumArray removeAllObjects];
        [_displayListTableView reloadData];
    }
    _productPageIndex=oldPageNum+1;
    [self requestDisplayList: _productPageIndex pageSize:6];
}
-(void)requestDisplayList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
         [params setObject:_searchTextField.text forKey:@"KeyWord"];
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<filterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[filterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:[selectFilterCodeArray objectAtIndex:i] forKey:@"FilterCode"];
            [mDocumentLine addObject:dic];
            
        }
        NSMutableArray *mDocumentLine1=[NSMutableArray array];
        for (int i=0; i<customTimeFilterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[customTimeFilterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:startTimeStr forKey:@"Value1"];
            [dic setValue:endTimeStr forKey:@"Value2"];
            [mDocumentLine1 addObject:dic];
            
        }

        [params setObject:mDocumentLine forKey:@"DataLineFileterParam"];
        [params setObject:mDocumentLine1 forKey:@"DataLineFileterParam2"];
        // NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"StoreManager/DCountList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                  //    NSLog(@"shopcartlist===%@",severDataDict.dataDict);
                    _productTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _displayTotalCount.text=[NSString stringWithFormat:@"有%lu条记录",(unsigned long)_productTotalCount];
                    
                    if (_productTotalCount%6!=0) {
                        _productTotalPage=_productTotalCount/6+1;
                    }
                    else if (_productTotalCount%6==0)
                    {
                        _productTotalPage=_productTotalCount/6;
                    }
                    
                    NSMutableArray  *displayListArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    //   int total=0;
                    if ( displayListArray.count>0) {
                        for (int i=0; i< displayListArray.count; i++) {
                            [displayNumArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocNum"]];
                            [displayWeightArray  addObject:[[displayListArray objectAtIndex:i] objectForKey:@"GramTotal"]];
                            [displayNumberArray  addObject:[[displayListArray objectAtIndex:i] objectForKey:@"Number"]];
                            [displayProductNameArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"ItemName"]];
                            [displayGuideNameArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"UserName"]];
                            [displayDateArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocDate"]];
                            [displayStatusArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocType"]];
                            [displayPriceArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocTotal"]];
                            
                        }
                    }
                   
                    [_displayListTableView reloadData];
                
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                       [Global loginViewController:self noteStr:requestResultStr];
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (_refreshHeaderView == nil) {
        
        EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _displayListTableView.bounds.size.height, self.view.frame.size.width, _displayListTableView.bounds.size.height)];
        view.delegate = self;
        [_displayListTableView addSubview:view];
        _refreshHeaderView = view;
        
        
    }
    
    //  update the last update date
    [_refreshHeaderView refreshLastUpdatedDate];
    // Do any additional setup after loading the view from its nib.
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    [displayNumArray removeAllObjects];
    [displayWeightArray removeAllObjects];
    [displayNumberArray removeAllObjects];
    [displayProductNameArray removeAllObjects];
    [displayGuideNameArray removeAllObjects];
    [displayDateArray removeAllObjects];
    [displayStatusArray removeAllObjects];
    [displayPriceArray removeAllObjects];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    
}

- (void)doneLoadingTableViewData{
    
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_displayListTableView];
    
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView==_displayListTableView)
    {
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
    }
    
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (scrollView==_displayListTableView)
    {
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    }
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return _reloading; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //    NSMutableArray *codeArrays = [NSMutableArray arrayWithArray:[shopCartData objectForKey:@"PRODUCTCODE"]];
    //    return [codeArrays count];
    if (tableView ==_displayListTableView) {
        return displayNumArray.count;
    }
    else if (tableView==_resultTableView)
    {
        return selectedProductCodeArray.count;
    }
//    else if (tableView==_resultTableView)
//    {
//        return selectedProductCodeArray.count;
//    }

    else if (tableView==_resultGuideListTableView)
    {
        return guideCodeArray.count;
    }
    else if (tableView==_detailTableView)
    {
        return detailUrlArray.count;
    }

    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView==_displayListTableView||tableView==_resultTableView||tableView==_detailTableView)
        return 120.0f;
    return 55;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_displayListTableView) {
        static NSString * identifier = @"Cell";
        ProductDisplayTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ProductDisplayTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
            // cell.delegate=self;
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (displayNumArray.count>0) {
            cell.numLabel.text=[NSString stringWithFormat:@"%@",[displayNumArray objectAtIndex:indexPath.row]];
           // [self resizeLabel:cell.numLabel];
            [Global resizeForLable:cell.numLabel WithText:cell.numLabel.text parentView:self.view];
            CGRect frame=cell.statusLabel.frame;
            frame.origin.x=cell.numLabel.frame.origin.x+cell.numLabel.frame.size.width-15;
            cell.statusLabel.frame=frame;
        }
        if (displayStatusArray.count>0) {
            NSString *statusStr=[displayStatusArray objectAtIndex:indexPath.row];
            cell.statusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
            if ([statusStr isEqualToString:@"上柜"]) {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                cell.tagLabel.text=@"上柜产品";
            }
            else
            {
                 [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                
                cell.tagLabel.text=@"下柜产品";
            }
        }


        if (displayPriceArray.count>0) {
            float AvgPrice=[[displayPriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            //  NSString *marketStr=[NSString stringWithFormat:@"¥%0.02f",[[inquiryPriceArray objectAtIndex:indexPath.row] floatValue]];
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];//[shopCartMarketArray objectAtIndex:indexPath.row];
//            cell.priceLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[displayPriceArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (displayDateArray.count>0) {
            cell.dateLabel.text=[displayDateArray objectAtIndex:indexPath.row];
        }
        if (displayGuideNameArray.count>0) {
            NSString *guideNameStr=[displayGuideNameArray objectAtIndex:indexPath.row];
            if (guideNameStr.length>0) {
                cell.guideNameLabel.text=guideNameStr;
            }
           else
           {
               cell.guideNameLabel.text=@"未填写";
           }
            [Global resizeForLable:cell.guideNameLabel WithText:cell.guideNameLabel.text parentView:self.view];
         //   [self resizeLabel:cell.guideNameLabel];
            CGRect frame=cell.dateTagLabel.frame;
            frame.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+15;
            cell.dateTagLabel.frame=frame;
            
            CGRect frame1=cell.dateLabel.frame;
            frame1.origin.x=cell.dateTagLabel.frame.origin.x+cell.dateTagLabel.frame.size.width+3;
            cell.dateLabel.frame=frame1;


        }
        NSString *numberStr=@"";
        NSString *weightStr=@"";
        NSString *nameStr=@"";
        if (displayNumberArray.count>0) {
            numberStr=[NSString stringWithFormat:@"%ld",(long)[[displayNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (displayWeightArray.count>0) {
            weightStr=[NSString stringWithFormat:@"%0.02f",[[displayWeightArray objectAtIndex:indexPath.row] floatValue]];
        }

        if (displayProductNameArray.count>0) {
            nameStr=[NSString stringWithFormat:@"%@",[displayProductNameArray objectAtIndex:indexPath.row]];
          //  cell.productNameLabel.text=nameStr;//[shopCartMarketArray objectAtIndex:indexPath.row];
            if ([numberStr floatValue]>1) {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@...  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            else
            {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            [Global resizeForLable:cell.productNameLabel WithText:cell.productNameLabel.text parentView:self.view];
           //  [self resizeLabel:cell.productNameLabel];
            
            CGRect frame=cell.priceTagLabel.frame;
            frame.origin.x=cell.productNameLabel.frame.origin.x+cell.productNameLabel.frame.size.width+17;
            cell.priceTagLabel.frame=frame;
            
            CGRect frame1=cell.priceLabel.frame;
            frame1.origin.x=cell.priceTagLabel.frame.origin.x+cell.priceTagLabel.frame.size.width+3;
            cell.priceLabel.frame=frame1;

        }
        
        
        if (indexPath.row == [displayNumArray count] - 1)
        {
            if (_productPageIndex<=_productTotalPage) {
                //    NSLog(@"###LOADING???");
                [self loadProductNextPage:_productPageIndex];
            }
            
        }
        return cell;
    }
    else if (tableView==_resultTableView)
    {
        static NSString * const  ResultTableViewCellIdentifier = @"ResultTableViewCellIdentifier";
        UpCounterDetailTableViewCell *cell=( UpCounterDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ResultTableViewCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"UpCounterDetailTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.receiverLabel.hidden=YES;
        cell.receiverTagLabel.hidden=YES;
    
        
        CGRect frame= cell.weightTagLabel.frame;
        //            if ([[detailAttributesArray objectAtIndex:indexPath.row] length]>0) {
        //
        //                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width+12;
        //            }
        //            else
        //            {
        frame.origin.x=96;
        //}
        cell.weightTagLabel.frame=frame;
        
        CGRect frame1= cell.resultProductWeightLabel.frame;
        frame1.origin.x=cell.weightTagLabel.frame.origin.x+cell.weightTagLabel.frame.size.width+1;
        cell.resultProductWeightLabel.frame=frame1;
        
        

        if (selectedProductImageArray.count>0) {
            if ([[selectedProductImageArray objectAtIndex:indexPath.row] length]>0) {
                
            [cell.resultProductImageView setImageWithURL:[NSURL URLWithString:[selectedProductImageArray objectAtIndex:indexPath.row]]];
            }
            else
            {
            [cell.resultProductImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (selectedProductWeightArray.count>0) {
            cell.resultProductWeightLabel.text=[NSString stringWithFormat:@"%@g",[selectedProductWeightArray objectAtIndex:indexPath.row]];
           // [self resizeLabel:cell.resultProductWeightLabel];
            [Global resizeForLable:cell.resultProductWeightLabel WithText:cell.resultProductWeightLabel.text parentView:self.view];
            CGRect frame1=cell.resultProductPriceLabel.frame;
            frame1.origin.x=cell.resultProductWeightLabel.frame.origin.x+cell.resultProductWeightLabel.frame.size.width+10;
            cell.resultProductPriceLabel.frame=frame1;

        }
        if (selectedProductPriceArray.count>0) {
            float AvgPrice=[[selectedProductPriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            cell.resultProductPriceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
        }
        if (selectedProductNameArray.count>0) {
            cell.resultProductNameLabel.text=[NSString stringWithFormat:@"%@ %@",[selectedProductCodeArray objectAtIndex:indexPath.row],[selectedProductNameArray objectAtIndex:indexPath.row]];//[selectedProductNameArray objectAtIndex:indexPath.row];
        }
        if (selectProductWhereArray.count>0) {
            cell.storeAddressLabel.text=[selectProductWhereArray objectAtIndex:indexPath.row];
        }
        cell.dotLineLabel.hidden=NO;
        if (indexPath.row==selectedProductCodeArray.count-1) {
            cell.dotLineLabel.hidden=YES;
        }
        
        return cell;
        
    }

    else if (tableView==_resultGuideListTableView)
    {
        static NSString * const  GuideListIdentifier = @"GuideListCellIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: GuideListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (guideNameArray.count>0) {
            cell.guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }
    else if (tableView==_detailTableView)
    {
        static NSString * const  ChangeTableViewCellIdentifier = @"ChangeTableViewCellIdentifier";
        UpCounterDetailTableViewCell *cell=( UpCounterDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ChangeTableViewCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"UpCounterDetailTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.receiverLabel.hidden=YES;
        cell.receiverTagLabel.hidden=YES;
        
        if (detailUrlArray.count>0) {
            if ([[detailUrlArray objectAtIndex:indexPath.row] length]>0) {
              [cell.resultProductImageView setImageWithURL:[NSURL URLWithString:[detailUrlArray objectAtIndex:indexPath.row]]];
            }
            else
            {
            [cell.resultProductImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (detailAttributesArray.count>0) {
            if ([detailAttributesArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                cell.attributesLabel.text=[NSString stringWithFormat:@"%@",[detailAttributesArray objectAtIndex:indexPath.row]];
                
            }
         //   [self resizeLabel: cell.attributesLabel];
           [Global resizeForLable:cell.attributesLabel WithText:cell.attributesLabel.text parentView:self.view];
            CGRect frame= cell.weightTagLabel.frame;
            if ([[detailAttributesArray objectAtIndex:indexPath.row] length]>0) {
                
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width+12;
            }
            else
            {
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width;
            }
            cell.weightTagLabel.frame=frame;
            
            CGRect frame1= cell.resultProductWeightLabel.frame;
            frame1.origin.x=cell.weightTagLabel.frame.origin.x+cell.weightTagLabel.frame.size.width+1;
            cell.resultProductWeightLabel.frame=frame1;
            
        }

        if (detailWeightArray.count>0) {
            cell.resultProductWeightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[detailWeightArray objectAtIndex:indexPath.row] floatValue]];
           // [self resizeLabel: cell.resultProductWeightLabel];
             [Global resizeForLable:cell.resultProductWeightLabel WithText:cell.resultProductWeightLabel.text parentView:self.view];
        }
        if (detailWhereArray.count>0) {
            cell.storeAddressLabel.text=[detailWhereArray objectAtIndex:indexPath.row];
        }
        if (detailLinePriceArray.count>0) {
            cell.resultProductPriceLabel.text=[NSString stringWithFormat:@"¥%@",[detailLinePriceArray objectAtIndex:indexPath.row]];
            CGRect frame=cell.resultProductPriceLabel.frame;
            frame.origin.x=cell.resultProductWeightLabel.frame.origin.x+cell.resultProductWeightLabel.frame.size.width+10;
            cell.resultProductPriceLabel.frame=frame;
        }
        if (detailProductNameArray.count>0) {
            cell.resultProductNameLabel.text=[NSString stringWithFormat:@"%@ %@",[detailProductCodeArray objectAtIndex:indexPath.row],[detailProductNameArray objectAtIndex:indexPath.row]];//[detailProductNameArray objectAtIndex:indexPath.row];
        }
         cell.dotLineLabel.hidden=NO;
        if (indexPath.row==detailUrlArray.count-1) {
            cell.dotLineLabel.hidden=YES;
        }
        return cell;
        
    }

    return nil;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_resultTableView) {
         return YES;
    }
    return NO;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_resultTableView) {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            
            [selectedProductImageArray removeObjectAtIndex:indexPath.row];
            [selectedProductWeightArray removeObjectAtIndex:indexPath.row];
            [selectedProductPriceArray removeObjectAtIndex:indexPath.row];
            [selectedProductNameArray removeObjectAtIndex:indexPath.row];
            [selectedProductCodeArray removeObjectAtIndex:indexPath.row];
            [selectProductWhereArray removeObjectAtIndex:indexPath.row];
            
            [_resultTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
          //  [tableView reloadData];
            float total=0.0f;
            for (int i=0; i<selectedProductWeightArray.count; i++) {
                total=total+[[selectedProductWeightArray objectAtIndex:i] floatValue];
            }
            
            _lastTotalLabel.text=[NSString stringWithFormat:@"共%lu件,%0.02fg",(unsigned long)selectedProductWeightArray.count,total];
            

            CGRect frame1=_resultTableView.frame;
            frame1.size.height=120*selectedProductCodeArray.count;
            _resultTableView.frame=frame1;
            
           
            CGRect frame2=_lastView.frame;
            frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
            _lastView.frame=frame2;
//            if (_lastView.frame.size.height+_lastView.frame.origin.y>700) {
//                CGRect frame3=_lastView1.frame;
//                frame3.origin.y=_lastView.frame.origin.y+_lastView.frame.size.height+10;
//                _lastView1.frame=frame3;
//            }
//            else
//            {
//                CGRect frame3=_lastView1.frame;
//                frame3.origin.y=704;
//                _lastView1.frame=frame3;
//
//            }
            [_resultScrollview setContentSize:CGSizeMake(0, _lastView.frame.origin.y+ _lastView.frame.size.height+50)];
            [_resultScrollview setScrollEnabled:YES];
    }
//                else if (editingStyle == UITableViewCellEditingStyleInsert) {
//                    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
//                }

    }
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"删除";
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
      if (tableView==_resultGuideListTableView) {
        guideCodeStr=[guideCodeArray objectAtIndex:indexPath.row];
        
        _resultGuideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_resultGuideListArrowImage setImage:closeImage];
            CGRect frame=_resultGuideListViewContainer.frame;
            
            frame.size.height=1;
            [_resultGuideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            guideIsOpen=NO;
        }];
        _resultGuideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
          [Global resizeForLable:_resultGuideNameLabel WithText:_resultGuideNameLabel.text parentView:self.view];
          CGRect frameK=_resultGuideNameLabel.frame;
          frameK.origin.x=_resultGuideListArrowImage.frame.origin.x-frameK.size.width-5;
          _resultGuideNameLabel.frame=frameK;

    }
    else if (tableView==_detailTableView)
    {
        _isLoad=@"Y";
        if (commonProductDetailVC.view!=nil) {
            
            [commonProductDetailVC removeFromParentViewController];
            [commonProductDetailVC.view removeFromSuperview];
            
        }
        commonProductDetailVC=[[CommonProductDetailViewController alloc] init];
        commonProductDetailVC.delegate=self;
        commonProductDetailVC.codeStr=[detailProductCodeArray objectAtIndex:indexPath.row];
        commonProductDetailVC.view.frame = CGRectMake(0,
                                                      0,
                                                      self.view.bounds.size.width,
                                                      self.view.bounds.size.height);
        
        [self addChildViewController:commonProductDetailVC];
        [self.view addSubview:commonProductDetailVC.view];
    }
    else if (tableView==_displayListTableView)
    {
        [detailUrlArray removeAllObjects];
        [detailProductNameArray removeAllObjects];
        [detailProductCodeArray removeAllObjects];
//        NSString *lineTotalStr=[NSString stringWithFormat:@"%0.02f",[[[returnDataLineArray objectAtIndex:i] objectForKey:@"LineTotal"] floatValue]];
        [detailLinePriceArray removeAllObjects];
        [detailWhereArray removeAllObjects];
        [detailWeightArray removeAllObjects];
        [detailAttributesArray removeAllObjects];
        [self requestDetail:[displayNumArray objectAtIndex:indexPath.row] styleStr:[displayStatusArray objectAtIndex:indexPath.row]];
        _detailTitleLabel.text=[NSString stringWithFormat:@"%@详情",[displayStatusArray objectAtIndex:indexPath.row]];
        [UIView animateWithDuration:0.5 animations:^{
            
            
            CGRect frame=_upCounterDetailViewContainer.frame;
            
            frame.origin.y=0;
            [_upCounterDetailViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            
        }];

    }
}
-(void)commonProductDetailShopCartClick
{
    if ([self.delegate respondsToSelector:@selector(ProductDisplayShopCtarClick)]) {
        
        [self.delegate ProductDisplayShopCtarClick];
    }
    
}

-(void)requestDetail:(NSString *)codeStr styleStr:(NSString *)styleStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:codeStr forKey:@"DocNum"];
        [HttpRequest requestData:@"StoreManager/GetCounter" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                  //  NSLog(@"222=%@",severDataDict.dataDict);
                    _detailTotalLabel.text=[NSString stringWithFormat:@"(共%ld件,%0.02fg)",(long)[[severDataDict.dataDict objectForKey:@"Number"] integerValue],[[severDataDict.dataDict objectForKey:@"GramTotal"] floatValue]];
                    _detailNumLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
                     _detailGuideNameLabel.text=[severDataDict.dataDict objectForKey:@"UserName"];
                    //[self resizeLabel:_detailGuideNameLabel];
                    [Global resizeForLable:_detailGuideNameLabel WithText:_detailGuideNameLabel.text parentView:self.view];
                    _detailTextView.text=[severDataDict.dataDict objectForKey:@"Remark"];
                    //[Global resizeTextView:_detailTextView contentStr:_detailTextView.text];
                    CGFloat height=  [Global heightForTextView:_detailTextView WithText:_detailTextView.text];
                    
                    CGRect frameA=_detailTextView.frame;
                    frameA.size.height=height;
                    _detailTextView.frame=frameA;
                    CGRect frameD=_detailLastView.frame;
                    frameD.size.height=_detailTextView.frame.origin.y+_detailTextView.frame.size.height+10;
                    _detailLastView.frame=frameD;
                    
                   // _detailStyleLabel.text=styleStr;
                    _detailDateNameLabel.text=[severDataDict.dataDict objectForKey:@"DocDate"];
                   // _detailProductTypeLabel.text=@"无";//[severDataDict.dataDict objectForKey:@"DocType"];
                   // [self resizeLabel:_detailProductTypeLabel];
                    NSString *storeNameStr=[severDataDict.dataDict objectForKey:@"StoreName"];
                    _detailStoreNameLabel.text=storeNameStr;
                   // [self resizeLabel:_detailStoreNameLabel];
                    [Global resizeForLable:_detailStoreNameLabel WithText:_detailStoreNameLabel.text parentView:self.view];
                    CGRect frame3=_detailStoreNameTagLabel.frame;
                    frame3.origin.x=_detailGuideNameLabel.frame.origin.x+_detailGuideNameLabel.frame.size.width+12;
                    _detailStoreNameTagLabel.frame=frame3;
                    
                    CGRect frame4=_detailStoreNameLabel.frame;
                    frame4.origin.x=_detailStoreNameTagLabel.frame.origin.x+_detailStoreNameTagLabel.frame.size.width+3;
                    _detailStoreNameLabel.frame=frame4;

                    
                    NSMutableArray *returnDataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    float returnMonney=0;
                    for (int i=0; i<returnDataLineArray.count; i++) {
                        [detailUrlArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ImageUrl"]];
                        [detailProductCodeArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ItemCode"]];
                        [detailProductNameArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ItemName"]];
                        NSString *lineTotalStr=[NSString stringWithFormat:@"%0.02f",[[[returnDataLineArray objectAtIndex:i] objectForKey:@"Price"] floatValue]];
                        [detailLinePriceArray addObject:lineTotalStr];
                        returnMonney=returnMonney+[lineTotalStr floatValue];
                      //  NSString *weightStr=[NSString stringWithFormat:@"%d",[[[returnDataLineArray objectAtIndex:i] objectForKey:@"Gram"] intValue]];
                        [detailWeightArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"Gram"]];
                        [detailWhereArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"WhsName"]];
                        [detailAttributesArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"Attributes"]];
                        
                    }
                   
                    [_detailTableView reloadData];
                   
                    CGRect frame1=_detailTableView.frame;
                    frame1.size.height=120*detailUrlArray.count;
                    _detailTableView.frame=frame1;
                    
                    CGRect frame2=_detailLastView.frame;
                    frame2.origin.y=_detailTableView.frame.origin.y+_detailTableView.frame.size.height+10;
                    _detailLastView.frame=frame2;
                    
                    
                    
                    [_detailScrollview setContentSize:CGSizeMake(0, _detailLastView.frame.origin.y+ _detailLastView.frame.size.height)];
                    [_detailScrollview setScrollEnabled:YES];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                      [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    if (textField==_resultTextField)
    {
       // [self performSelector:@selector(textClick) withObject:nil afterDelay:0.1];
        
        CGRect viewFrame1=_upCounterViewContainer.frame;
        viewFrame1.origin.y=0;
        _upCounterViewContainer.frame=viewFrame1;
        
       
        [UIView animateWithDuration:0.5 animations:^{
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_resultGuideListArrowImage setImage:closeImage];
            
           
            
        } completion:^(BOOL finished){
            guideIsOpen=NO;
        }];
       
    }
        return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if(textField==_resultTextField)
    {
        [self findProductList:_resultTextField.text];
        _resultTextField.text=@"";
    }
    if (textField==_searchTextField) {
        [displayNumArray removeAllObjects];
        [displayWeightArray removeAllObjects];
        [displayNumberArray removeAllObjects];
        [displayProductNameArray removeAllObjects];
        [displayGuideNameArray removeAllObjects];
        [displayDateArray removeAllObjects];
        [displayStatusArray removeAllObjects];
        [displayPriceArray removeAllObjects];

        _productPageIndex=0;
        [self loadProductNextPage:_productPageIndex];
        [_searchTextField resignFirstResponder];
    }

    return YES;
}
-(IBAction)addScanBtnClick :(id)sender
{
     [_resultTextField resignFirstResponder];
    if (commonScanVC.view!=nil) {
        
        [commonScanVC removeFromParentViewController];
        [commonScanVC.view removeFromSuperview];
        
    }
    commonScanVC=[[CommonScanViewController alloc] init];
    commonScanVC.delegate=self;
    
    commonScanVC.view.frame = CGRectMake(0,
                                         0,
                                         self.view.bounds.size.width,
                                         self.view.bounds.size.height);
    
    [self addChildViewController:commonScanVC];
    [self.view addSubview:commonScanVC.view];
    
}
-(void)CommonScanResult:(NSString *)codeStr
{
    //NSLog(@"codeStr=====%@",codeStr);
    if (commonScanVC.view!=nil) {
        //   NSLog(@"dddddddd");
        [commonScanVC removeFromParentViewController];
        [commonScanVC.view removeFromSuperview];
        
    }
    [self findProductList:codeStr];
    
}

-(void)findProductList:(NSString *)codeStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:codeStr forKey:@"KeyWord"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:1];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:1];
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:typeStr forKey:@"BType"];
      //  NSLog(@"eeeeee===%@",params);
        [HttpRequest requestData:@"Product/GetPItemList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
           
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                   // NSLog(@"ddddd===%@",severDataDict.dataDict);
                     _resultNoteView.hidden=YES;
                    NSMutableArray *dataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    if (![selectedProductCodeArray containsObject:codeStr]) {
                         for (int i=0; i< dataLineArray.count; i++) {
                        [selectedProductCodeArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"ItemCode"]];
                        
                        NSString *urlStr=[[dataLineArray objectAtIndex:i] objectForKey:@"ImageUrl"];
                        [selectedProductImageArray addObject:urlStr];
                        [selectedProductWeightArray addObject:[NSString stringWithFormat:@"%0.02f",[[[dataLineArray objectAtIndex:i] objectForKey:@"Gram"] floatValue]]];
                        [selectedProductPriceArray addObject:[NSString stringWithFormat:@"%0.02f",[[[dataLineArray objectAtIndex:i] objectForKey:@"Price"] floatValue]]];
                        [selectedProductNameArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"ItemName"]];
                        [selectProductWhereArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"WhsName"]];
                         }
                    }
                     [_resultTableView  reloadData];
                    CGRect frame1=_resultTableView.frame;
                    frame1.size.height=120*selectedProductCodeArray.count;
                    _resultTableView.frame=frame1;
                    
                   
                    
                    float total=0.0f;
                    for (int i=0; i<selectedProductWeightArray.count; i++) {
                        total=total+[[selectedProductWeightArray objectAtIndex:i] floatValue];
                    }
                    
                    _lastTotalLabel.text=[NSString stringWithFormat:@"共%lu件,%0.02fg",(unsigned long)selectedProductWeightArray.count,total];
                    
                    CGRect frame2=_lastView.frame;
                    frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
                    _lastView.frame=frame2;
                    
                    [_resultScrollview setContentSize:CGSizeMake(0, _lastView.frame.origin.y+ _lastView.frame.size.height+50)];
                    [_resultScrollview setScrollEnabled:YES];
                    }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                   
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}
-(IBAction)confirmUpCounterBtnClick:(id)sender
{
    if (guideCodeStr.length>0) {
        
        
        if ([Global getLoginToken].length>0) {
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            NSMutableArray *mDocumentLine=[NSMutableArray array];
           
            //        NSLog(@"findSkuAllCountArray===%@",findSkuAllCountArray);
            for (int i=0; i<selectedProductCodeArray.count; i++) {
               
                    NSString *codeStr =[selectedProductCodeArray objectAtIndex:i];
                    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                    //    NSLog(@"codeContentssss==%@",codeContent);
                    [dic setValue:codeStr forKey:@"ItemCode"];
                    [mDocumentLine addObject:dic];
                           }
            NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
            [params setObject:[Global getLoginToken] forKey:@"Token"];
            [params setObject:guideCodeStr forKey:@"GuideCode"];
            [params setObject:_resultTextView.text forKey:@"Remark"];
           [params setObject:upOrDownCounterStr forKey:@"DocType"];
            
            [params setObject:mDocumentLine forKey:@"DataLine"];
            
            // NSLog(@"productStockPARAM===%@",params);
            [HttpRequest requestData:@"StoreManager/Count" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                // [Global hideProgressHUDInternal:self.view];
                if (isSuccess) {
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                      //  NSLog(@"111==%@",severDataDict.dataDict);
                        CGRect viewFrame1=_upCounterViewContainer.frame;
                        viewFrame1.origin.y=768;
                        _upCounterViewContainer.frame=viewFrame1;
                        
                        [selectedProductImageArray removeAllObjects];
                        
                        [selectedProductWeightArray removeAllObjects];
                        [selectedProductPriceArray removeAllObjects];
                        [selectedProductNameArray removeAllObjects];
                        [selectProductWhereArray removeAllObjects];
                        [selectedProductCodeArray removeAllObjects];
                        [_resultTableView reloadData];
                        _resultGuideNameLabel.text=@"";
                        guideCodeStr=@"";
                        
                        [displayNumArray removeAllObjects];
                        [displayWeightArray removeAllObjects];
                        [displayNumberArray removeAllObjects];
                        [displayProductNameArray removeAllObjects];
                        [displayGuideNameArray removeAllObjects];
                        [displayDateArray removeAllObjects];
                        [displayStatusArray removeAllObjects];
                        [displayPriceArray removeAllObjects];

                        _productPageIndex=0;
                        [self loadProductNextPage:_productPageIndex];
                    }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        //  [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                           [Global loginViewController:self noteStr:requestResultStr]; 
                         //   [Global loginViewController:self];
                        }

                    }
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
            }];
            
        }
    }
    else
    {
     
            
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择导购" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
       
        
    }
}

- (void)textViewDidChange:(UITextView *)textView
{
    if (textView==_resultTextView) {
        if (textView.text.length == 0) {
            _resultTextViewImage.hidden=NO;
            _resultTextViewLabel.hidden=NO;
        }
        else
        {
            _resultTextViewImage.hidden=YES;
            _resultTextViewLabel.hidden=YES;
            
        }
        
    }
    
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if ((_lastView.frame.origin.y+_lastView.frame.size.height+_resultScrollview.contentOffset.y+352>768)) {
        
        
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_upCounterResultView.frame;
            viewFrame.origin.y=-(_lastView.frame.origin.y+_lastView.frame.size.height-_resultScrollview.contentOffset.y+370-768);
            _upCounterResultView.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];
    }

//    if (textView==_resultTextView) {
//        if (_lastView.frame.origin.y+_lastView.frame.size.height+352>768) {
//            
//       
//        [UIView animateWithDuration:0.3 animations:^{
//            CGRect viewFrame=_upCounterResultView.frame;
//            viewFrame.origin.y=-(_lastView.frame.origin.y+_lastView.frame.size.height+362-768);
//            _upCounterResultView.frame=viewFrame;
//        } completion:^(BOOL finished){
//            
//        }];
//        }
//        
//    }
//    
    
    return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
     [_resultScrollview setContentOffset:CGPointMake(0, 0)];
    if (textView==_resultTextView) {
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_upCounterResultView.frame;
            viewFrame.origin.y=0;
            _upCounterResultView.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];
        
    }
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
